package com.mask.userconsumer;

import feign.FeignException;
import feign.hystrix.FallbackFactory;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.stereotype.Component;

@Component
public class UserProviderBackFactory implements FallbackFactory<ConsumerApi> {

    @Override
    public ConsumerApi create(Throwable throwable) {
        return new ConsumerApi() {
            @Override
            public String alive() {
                System.out.println("1:"+throwable);
                if (throwable instanceof FeignException.NotFound){
                    return "远程服务器500";
                }
                System.out.println("2:"+ToStringBuilder.reflectionToString(throwable));

                throwable.printStackTrace();
                return "降级信息";
            }

            @Override
            public String getById(String name) {
                return null;
            }
        };
    }
}
